package com.xu.seckillkill.controller.impl;

import com.baomidou.mybatisplus.extension.api.R;
import com.xu.seckillkill.controller.PackageController;
import com.xu.seckillkill.pojo.GetPacketReq;
import com.xu.seckillkill.pojo.RedPacketInfo;
import com.xu.seckillkill.pojo.ReposBean;
import com.xu.seckillkill.pojo.Status;
import com.xu.seckillkill.service.PackageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @version v1.0
 * @类描述：
 * @项目名称：
 * @包名： com.xu.seckillkill.controller.impl
 * @类名称：PackageControllerImpl
 * @创建人：YIHANG.XU
 * @创建时间：2021/2/1411:16 下午
 * @修改人：YIHANG.XU
 * @修改时间：2021/2/1411:16 下午
 * @修改备注：
 * @Copyright
 */
@Slf4j
@RestController
@RequestMapping("/kill")
public class PackageControllerImpl implements PackageController {
    @Autowired
    private PackageService packageService;

    /**
     * 添加红包信息
     *
     * @param redPacketInfo
     * @return
     */
    @Override
    @RequestMapping("/addRedEnvelope")
    public ReposBean addRedEnvelope(@RequestBody RedPacketInfo redPacketInfo) {
        try {
            packageService.addRedEnvelope(redPacketInfo);
            return ReposBean.success();
        } catch (Exception exception) {
            log.error("红包发送出现问题");
            return ReposBean.error(Status.ERROR);
        }


    }

    /**
     * 抢红包
     *
     * @param req
     * @return
     */
    @Override
    @RequestMapping("/getRedPackage")
    public ReposBean getRedPackage(@RequestBody GetPacketReq req) {
        packageService.getRedPackage(req);
        return ReposBean.success();
    }

    @Override
    public void getPage() {
        packageService.getPage();
    }
}
